{% extends "base.html" %}

{% block title %}首页 - 头条自动发文系统{% endblock %}
{% block page_title %}系统概览{% endblock %}

{% block content %}
<div class="row">
    <!-- 系统状态卡片 -->
    <div class="col-md-3 mb-4">
        <div class="card text-center">
            <div class="card-body">
                <i class="fas fa-user-circle fa-2x text-primary mb-2"></i>
                <h5 class="card-title">账号状态</h5>
                {% if account %}
                <p class="card-text text-success">
                    <i class="fas fa-check-circle"></i>
                    已登录
                </p>
                {% else %}
                <p class="card-text text-warning">
                    <i class="fas fa-exclamation-circle"></i>
                    未登录
                </p>
                {% endif %}
            </div>
        </div>
    </div>
    
    <div class="col-md-3 mb-4">
        <div class="card text-center">
            <div class="card-body">
                <i class="fas fa-file-alt fa-2x text-success mb-2"></i>
                <h5 class="card-title">文章总数</h5>
                <p class="card-text">
                    <span class="h4">{{ articles|length }}</span>
                    <small class="text-muted">篇</small>
                </p>
            </div>
        </div>
    </div>
    
    <div class="col-md-3 mb-4">
        <div class="card text-center">
            <div class="card-body">
                <i class="fas fa-paper-plane fa-2x text-info mb-2"></i>
                <h5 class="card-title">已发布</h5>
                <p class="card-text">
                    <span class="h4">{{ articles|selectattr("status", "equalto", "published")|list|length }}</span>
                    <small class="text-muted">篇</small>
                </p>
            </div>
        </div>
    </div>
    
    <div class="col-md-3 mb-4">
        <div class="card text-center">
            <div class="card-body">
                <i class="fas fa-edit fa-2x text-warning mb-2"></i>
                <h5 class="card-title">草稿</h5>
                <p class="card-text">
                    <span class="h4">{{ articles|selectattr("status", "equalto", "draft")|list|length }}</span>
                    <small class="text-muted">篇</small>
                </p>
            </div>
        </div>
    </div>
</div>

<!-- 快速操作 -->
<div class="row mb-4">
    <div class="col-12">
        <div class="card">
            <div class="card-header">
                <h5 class="mb-0">
                    <i class="fas fa-bolt"></i>
                    快速操作
                </h5>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-3 mb-2">
                        <a href="/login" class="btn btn-outline-primary w-100">
                            <i class="fas fa-sign-in-alt"></i>
                            账号登录
                        </a>
                    </div>
                    <div class="col-md-3 mb-2">
                        <a href="/generate" class="btn btn-gradient w-100">
                            <i class="fas fa-magic"></i>
                            生成文章
                        </a>
                    </div>
                    <div class="col-md-3 mb-2">
                        <a href="/publish" class="btn btn-outline-success w-100">
                            <i class="fas fa-paper-plane"></i>
                            发布文章
                        </a>
                    </div>
                    <div class="col-md-3 mb-2">
                        <a href="/monitor" class="btn btn-outline-info w-100">
                            <i class="fas fa-chart-line"></i>
                            数据监控
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 最近文章 -->
<div class="row">
    <div class="col-12">
        <div class="card">
            <div class="card-header d-flex justify-content-between align-items-center">
                <h5 class="mb-0">
                    <i class="fas fa-clock"></i>
                    最近文章
                </h5>
                <a href="/publish" class="btn btn-sm btn-outline-primary">查看全部</a>
            </div>
            <div class="card-body">
                {% if articles %}
                <div class="table-responsive">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>标题</th>
                                <th>状态</th>
                                <th>创建时间</th>
                                <th>发布时间</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for article in articles[:5] %}
                            <tr>
                                <td>
                                    <div class="fw-bold">{{ article.title }}</div>
                                    <small class="text-muted">{{ article.content[:50] }}...</small>
                                </td>
                                <td>
                                    {% if article.status == 'published' %}
                                    <span class="badge bg-success status-badge">已发布</span>
                                    {% elif article.status == 'draft' %}
                                    <span class="badge bg-warning status-badge">草稿</span>
                                    {% else %}
                                    <span class="badge bg-secondary status-badge">{{ article.status }}</span>
                                    {% endif %}
                                </td>
                                <td>
                                    <small>{{ article.created_at[:16] }}</small>
                                </td>
                                <td>
                                    {% if article.published_at %}
                                    <small>{{ article.published_at[:16] }}</small>
                                    {% else %}
                                    <small class="text-muted">未发布</small>
                                    {% endif %}
                                </td>
                                <td>
                                    {% if article.status == 'draft' %}
                                    <a href="/publish?id={{ article.id }}" class="btn btn-sm btn-outline-primary">
                                        <i class="fas fa-paper-plane"></i>
                                        发布
                                    </a>
                                    {% elif article.status == 'published' %}
                                    <a href="/monitor?id={{ article.id }}" class="btn btn-sm btn-outline-info">
                                        <i class="fas fa-chart-line"></i>
                                        查看数据
                                    </a>
                                    {% endif %}
                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
                {% else %}
                <div class="text-center py-4">
                    <i class="fas fa-file-alt fa-3x text-muted mb-3"></i>
                    <p class="text-muted">还没有文章，<a href="/generate">立即生成</a>一篇吧！</p>
                </div>
                {% endif %}
            </div>
        </div>
    </div>
</div>

<!-- 使用说明 -->
<div class="row mt-4">
    <div class="col-12">
        <div class="card">
            <div class="card-header">
                <h5 class="mb-0">
                    <i class="fas fa-info-circle"></i>
                    使用说明
                </h5>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6">
                        <h6><i class="fas fa-user-plus text-primary"></i> 1. 账号登录</h6>
                        <p class="text-muted">首先需要登录头条账号，系统会生成二维码供您扫码登录。</p>
                        
                        <h6><i class="fas fa-magic text-success"></i> 2. 生成文章</h6>
                        <p class="text-muted">输入提示词，AI会自动生成符合头条发布格式的文章。</p>
                    </div>
                    <div class="col-md-6">
                        <h6><i class="fas fa-paper-plane text-info"></i> 3. 发布文章</h6>
                        <p class="text-muted">选择生成的文章进行发布，或者手动输入内容发布。</p>
                        
                        <h6><i class="fas fa-chart-line text-warning"></i> 4. 数据监控</h6>
                        <p class="text-muted">监控已发布文章的阅读量、点赞数、评论数等数据。</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
